<!-- Form ci_normal_ci START -->
<!--
1. You need Prototype javascript library to be included. Download it from http://www.prototypejs.org/
2. Image (animated gif) for waiting indicator have to be declared as follows:
Medium indicator. Javascript variable name ajax_waiting_indicator_medium_src. Example: var ajax_waiting_indicator_medium_src = 'img/indicator_medium.gif'
Please note that it is good idea image for the indicator to be preloaded (i.e. in onLoad page event).
3. Overlay image (normally png with some transperancy). Must be specified in css for  class ajax_overlay_form
4. CSS for the overlay div.
-->
<script type="text/javascript">
var _tm = '{$_tm}';
var _site_mode = {$_site_mode};
var _server_error_page = '{$_server_error_page}';
var _transit_vars_par = ''{foreach from=$_transit_vars item=tvar_value key=tvar_key} + '&' + '{$tvar_key}={$tvar_value}'{/foreach};

{literal}
function submit_ajax_ci_normal_ci() {
	var content = encodeURIComponent(FCKeditorAPI.GetInstance('ci_normal_ci_content').GetXHTML());
	var	pars = 'ci_normal_ci_content=' + content + '&' + 'ci_normal_ci_created=' + encodeURIComponent($F('ci_normal_ci_created')) + '&' + 'ci_normal_ci_form_id=' + encodeURIComponent($F('ci_normal_ci_form_id')) + '&' + 'ci_normal_ci_guard_value=' + encodeURIComponent($F('ci_normal_ci_guard_value')) + '&' +  'ci_normal_ci_submit=1' + '&' + '_tm=' + _tm + _transit_vars_par;

	fade_out_div();
	var myAjax = new Ajax.Request(
                                    "ajax/modules/tangra_cms/forms/ci_normal_ci_form.php",
                                    {
                                                method: 'post',
                                                onComplete: ci_normal_ci_result,
                                                onSuccess: ci_normal_ci_on_success,
                                                onFailure: ci_normal_ci_on_failure,
												parameters: pars
                                    }          );
}



function ci_normal_ci_result(req, json) {
	if (json) {
		var old_tm = _tm;
		_tm = json._tm;

		// refreshing _tm on all links that are outside of updated area
		for (var i=0; i < document.links.length; i++) {
 		  	document.links[i].href = document.links[i].href.replace(old_tm, _tm);
		}


		if (json.result_code == 1) { // OK
				switch(json.command) {
					case 'redirect':
						window.location = json.command_value;
						break;
					case 'show' :
					default :
						form_div = $('ci_normal_ci_form_div');
						form_div.innerHTML = req.responseText;
						break;
				}
		} else {
				// something is wrong
				if (_site_mode == 0) {
					//if in development mode - show the output anyway (if any).
					form_div = $('ci_normal_ci_form_div');
					form_div.innerHTML = req.responseText;
				}
		}
	} else {
		// no result_code, some serious error/exception occured.
		if (_site_mode == 1) {
			window.location = _server_error_page;
		} else {
			//if in development mode - show the output anyway (if any).
			form_div = $('ci_normal_ci_form_div');
			form_div.innerHTML = req.responseText;
		}
	}
}


function fade_out_div() {
	var overlay = $('ci_normal_ci_overlay');
	var top_div = $('ci_normal_ci_form_div');

	Position.clone(top_div, overlay)
	var image = $('ci_normal_ci_waiting');

	overlay.style.display = 'block';
	var image_top_offset = Math.round((overlay.offsetHeight - image.height) / 2);
	image.style.marginTop = image_top_offset + 'px';
}


function fade_in_div() {
	var overlay = $('ci_normal_ci_overlay');
	overlay.style.display = 'none';
}


function ci_normal_ci_on_success() {
	fade_in_div();
}


function ci_normal_ci_on_failure() {
	fade_in_div();
}

</script>

{/literal}
<div id="ci_normal_ci_form_div" style="width:800px;">
{include file="modules/tangra_cms/forms/ci_normal_ci_form.tpl"}
</div>
<div class="ajax_overlay_form" id="ci_normal_ci_overlay" style="display:none; position: absolute; z-index: 90;" align="center"><img src="img/modules/form_html_tpl_static_ajax_metallic/indicator_medium.gif" onclick="return true;" id="ci_normal_ci_waiting" alt="" /></div>
<!-- Form ci_normal_ci END -->
